<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="../layui/css/layui.css">
    <script src="../layui/layui.js"></script>
    <script src="../scripts/jquery.min.js"></script>
    <script src="../js/jquery-form.js"></script>

    <title>试题文件导入</title>
    <style>
        body{padding: 10px;}
        .change_size{
            height: 150px;
        }
        .for_check{

        }
    </style>
</head>

<body>

<input type="hidden" id="flag_manager" value=<%=session.getAttribute("flag_manager")%> />

<form  class="layui-form layui-form-pane1" id="subform" method="post">

    <div class="layui-form-item">
        <label class="layui-form-label">试题来源</label>
        <div class="layui-input-block">
            <input type="text" id="question_ori" name="question_ori"  lay-verify="required|title"  placeholder="请输入来源" autocomplete="off" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">试题科目</label>
        <div class="layui-input-block" >
            <select id="question_class" name="question_class" lay-filter="adminRole">
                <option value="">请选择科目</option>
                <option value="科一">科一</option>
                <option value="科四">科四</option>
            </select>
        </div>
    </div>



    <div class="layui-form-item">
        <label class="layui-form-label">上传excel文件</label>
        <div class="layui-input-block">
            <input type="file" name="file_content" id="file_content" accept="application/vnd.ms-excel" />
        </div>
    </div>





</form>
<br>
<div class="layui-form-item">
    <div class="layui-input-block">
        <button class="layui-btn" id="add_btn" onclick="to_submit()" >立即添加</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</div>


<script>
    //加载layui信息
    var form;
    layui.use('form', function(){
        form = layui.form;
        //layui日期选择
        layui.use('laydate', function(){
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#createTime', //指定元素
                value: new Date()
            });
        });
    });

    var layer;
    layui.use('layer', function(){
        layer = layui.layer;

    })

    function to_submit(){
        var file_content=$("#file_content").val();
        var question_class=$("#question_class").val();
        var question_ori=$("#question_ori").val();

        if(question_ori==""){
            layer.msg("来源不能为空");
            return ;
        }
        if(question_class==""){
            layer.msg("科目不能为空");
            return ;
        }
        if(file_content==""){
            layer.msg("您还没有选择文件");
            return ;
        }

        if($("#flag_manager").val()!="null"){
            ajaxFile("${pageContext.request.contextPath}/question/question_table_file_add.do");
        }else{
            layer.msg("添加失败，您不是管理员");
        }

    }
    function ajaxFile(url){

        $("#subform").ajaxSubmit({
            url:url,
            type:"post",
            enctype:'multipart/form-data',
            success:function(data){
                // if(data!=-1)
                //   layer.alert(data+"条数据已成功添加到数据库",{icon:1});
                // else
                //     layer.alert("文件不符合要求");
                layer.msg("数据已成功添加到数据库",{icon:1});
            }
        })
    }



</script>

</body>
</html>
